@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.invitingAdvertList')}}">招商广告</a>
            <em>
                >
            </em>
            <a href="{{route('Admin.Home.invitingAdvertClassifyList')}}">招商分类列表</a>

        </div>
        @include("admin.common.inviting-advert-header")
        <div class="filter-box clearfix">
            <div class="fr">
                <a class="addBtn" href="javascript:;" onclick="upPop(0)">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>分类名</th>
                    <th>操作</th>

                </tr>
                </thead>
                <tbody>
                @if(count($classifies) > 0)
                    @foreach($classifies as $classify)
                        <tr id="classify_{{$classify->id}}">
                            <td>{{$classify->id}}</td>
                            <td>{{$classify->name}}</td>
                            <td><a href="javascript:void(0);" data-id="{{$classify->id}}" class="color2" onclick="upPop({{$classify}})">编辑</a>  <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$classify->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
        </div>
        <div class="pagelist" style="text-align: center;">
            <?php echo $classifies->render();?>
        </div>
    </div>
    <div class="upPop-box">
        <div class="backdrop"></div>
        <div id="upPop" class="info-pop tixian">
            <input type="hidden" name="id" id="classifyId" value=""/>
            <a class="close" href="javascript:void(0);"></a>
            <h3>招商分类设置</h3>
            <div class="fill-list">
                <span class="fill-tit">分类名称：</span>
                <input class="fill-ipt" type="text" name="name" id="name" value="">
            </div>

            <input type="hidden" name="id" id="classify_id" />
            <div class="fill-list">
                <span class="fill-tit">&nbsp;</span>
                <input class="fill-submit" type="button" id="subThisForm" value="提交">
            </div>
        </div>
    </div>

    <script>
        function upPop(obj){
            $('#classifyId').val(obj.id);
            $('#name').val(obj.name);
            $('.upPop-box').upPop();
        }
       $(function() {
           $(document).on('click', '#subThisForm', function () {
               var name = $('#name').val();
               var id = $('#classifyId').val();

               $.ajax({
                   url: '{{route("Api.Admin.sys.setInvitingAdvertClassify")}}',
                   type: 'post',
                   dataType: 'json',
                   data: {
                       name:name,
                       id:id
                   },
                   success: function (obj) {
                       if (obj.level == "success") {
                           noty({
                               text: obj.message, type: obj.level, timeout: 600,
                               callback: {
                                   afterClose:function(){
                                       window.location.reload();
                                   }
                               }
                           });
                       } else if (obj.level == "error") {
                           noty({text: obj.message, type: obj.level, timeout: 600});
                       }

                   },
                   error: function (obj) {
                       console.log(obj);
                   }
               });
           });
            $(document).on("click", ".del", function () {
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {
                            addClass: 'btn btn-primary', text: '确定', onClick: function ($noty) {
                                $noty.close();
                                $.ajax({
                                    url: '{{route('Api.Admin.sys.delInvitingAdvertClassify')}}',
                                    type: 'post',
                                    dataType: 'json',
                                    data: {id: id},
                                    success: function (obj) {
                                        if (obj.level == "success") {
                                            $("#classify_" + id).hide('slow');
                                        } else {
                                            noty({type: obj.level, text: obj.message, timeout: 600});
                                        }
                                    },
                                    error: function (obj) {
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {
                            addClass: 'btn btn-danger', text: '取消', onClick: function ($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });


    </script>
@endsection
